var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 验收表
    contract: [],

    // 实际铺贴面积
    ares: "",
    // 单价
    price: "",
    // 金额
    amount: "",
    // 用胶量
    consumption: "",
    // 厚度
    thickness: "",
    // 浆层厚度照片
    thicknessList: [],
    issuccessMask: false,
    tonzhi: false,
    typeIndex: 0,
    workList: [],
    issuccessMaskes: false,
    workobj1: {
      bricklayTotalSize: "",
      bricklayGlueDosage: "",
      superviseCheckProof: "",
      superviseCheckProof: [],
      bricklayPlaceProof: [],
      bricklayPanoramaProof: [],
      bricklaySpecificProof: [],

    },

    workobj2: {
      bricklayTotalSize: "",
      bricklayGlueDosage: "",
      superviseCheckProof: "",
      superviseCheckProof: [],
      bricklayPlaceProof: [],
      bricklayPanoramaProof: [],
      bricklaySpecificProof: [],

    },
    workobj3: {
      bricklayTotalSize: "",
      bricklayGlueDosage: "",
      superviseCheckProof: "",
      superviseCheckProof: [],
      bricklayPlaceProof: [],
      bricklayPanoramaProof: [],
      bricklaySpecificProof: [],

    }
  },

  bindtype(e) {
    let typeIndex = e.currentTarget.dataset.type
    this.setData({
      typeIndex: typeIndex
    })
  },


  gounplonecheck() {
    wx.navigateTo({
      url: '/shopowner/pages/unplonecheck/unplonecheck?orderId=' + this.data.orderId + '&&projectOrder=' + JSON.stringify(this.data.projectOrder)
    })
  },
  // 项目详情接口
  getOrderDetails(showmak) {
    let t = this
    wx.showLoading({
      title: '加载中。。。', //提示的内容
      mask: true //显示透明蒙层 防止触摸穿透
    })
    wx.request({
      url: app.globalData.Interfaceurl + 'getOrderDetails',
      method: "post",
      header: {
        "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
      },
      data: {
        userId: app.globalData.userId,
        // userId: 1569562832576524288,
        orderId: t.data.orderId,
      },
      success: res => {
        wx.hideLoading();
        let workList = res.data.workList.filter(item=>item.userId!='')
        workList.forEach(item => {

          if (item.superviseCheckProof != "") {
            item.superviseCheckProof = item.superviseCheckProof.split(",").map(item1 => this.data.Imageurl + item1)
          } else {
            item.superviseCheckProof = []
          }



          if (item.bricklaySlurryThicknessProof != "") {
            item.bricklaySlurryThicknessProof = item.bricklaySlurryThicknessProof.split(",").map(item1 => this.data.Imageurl + item1)
          } else {
            item.bricklaySlurryThicknessProof = []
          }



          if (item.bricklayPlaceProof != "") {
            item.bricklayPlaceProof = item.bricklayPlaceProof.split(",").map(item1 => this.data.Imageurl + item1)
          } else {
            item.bricklayPlaceProof = []
          }


          if (item.bricklayPanoramaProof != "") {
            item.bricklayPanoramaProof = item.bricklayPanoramaProof.split(",").map(item1 => this.data.Imageurl + item1)
          } else {
            item.bricklayPlaceProof = []
          }

          if (item.bricklaySpecificProof != "") {
            item.bricklaySpecificProof = item.bricklaySpecificProof.split(",").map(item1 => this.data.Imageurl + item1)
          } else {
            item.bricklaySpecificProof = []
          }
          item.ishsow = true
        });


        let one = workList.filter(item => item.workType == 1)

        if (one.length != 0) {
          one.forEach(item => {
            if (item.superviseCheckProof!='') {
              let workobj1 = {
                bricklayTotalSize: item.bricklayTotalSize,
                bricklayGlueDosage: item.bricklayGlueDosage,
                superviseCheckProof: item.superviseCheckProof,
                superviseCheckProof: item.superviseCheckProof,
                bricklayPlaceProof: item.bricklayPlaceProof,
                bricklayPanoramaProof: item.bricklayPanoramaProof,
                bricklaySpecificProof: item.bricklaySpecificProof,
              }
              this.setData({
                workobj1: workobj1
              })
            }
          })
        }
        let two = workList.filter(item => item.workType == 2)
        if (two.length != 0) {
          two.forEach(item=>{
            if(item.superviseCheckProof!=''){
              let workobj2 = {
                bricklayTotalSize: item.bricklayTotalSize,
                bricklayGlueDosage: item.bricklayGlueDosage,
                superviseCheckProof: item.superviseCheckProof,
                superviseCheckProof: item.superviseCheckProof,
                bricklayPlaceProof: item.bricklayPlaceProof,
                bricklayPanoramaProof: item.bricklayPanoramaProof,
                bricklaySpecificProof: item.bricklaySpecificProof,
              }
              this.setData({
                workobj2: workobj2
              })
            }
          })
        }
        let treen = workList.filter(item => item.workType == 3)
        if (treen.length != 0) {
        treen.forEach(item=>{
          if(item.superviseCheckProof!=''){
            let workobj3 = {
              bricklayTotalSize: item.bricklayTotalSize,
              bricklayGlueDosage: item.bricklayGlueDosage,
              superviseCheckProof: item.superviseCheckProof,
              superviseCheckProof: item.superviseCheckProof,
              bricklayPlaceProof: item.bricklayPlaceProof,
              bricklayPanoramaProof: item.bricklayPanoramaProof,
              bricklaySpecificProof: item.bricklaySpecificProof,
            }
            this.setData({
              workobj3: workobj3
            })
          }
        })
        }

        t.setData({
          workList: workList,
          projectOrder: res.data.projectOrder,

        })







      },
      fail: err => {
        wx.showToast({
          title: '请求失败',
          duration: 2500, //持续的时间
            icon: 'none', //图标
        })
      }
    })
  },












  fakeCallback() { },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {

    let date = new Date()
    let year = date.getFullYear()
    let mouth = date.getMonth() + 1
    mouth = mouth >= 10 ? mouth : "0" + mouth
    let d = date.getDate()
    d = d >= 10 ? d : "0" + d
    let nowday = year + "-" + mouth + "-" + d









    this.setData({
      orderId: options.orderId,
      nowday: nowday,
      token: app.token(),
      Imageurl: app.globalData.Imageurl,
      // workList: workList,
    })


    this.getOrderDetails()
    if (options.todo) {
      this.setData({
        todo: options.todo
      })
    }
    if (options.todo == 'previewacceptance') {
      this.getOrderDetails()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.setStorageSync('up', false)
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {
    wx.removeStorageSync("up")
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
    wx.removeStorageSync("up")
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})